package data_structures;

import Utilities.Constants;

/**
 * Represents a discrete hyper-parameter.
 */
public class DiscreteHP implements HyperParameter {

	private int lowerBound;
	private int upperBound;
	private int value;

	public DiscreteHP(int lowerBound, int upperBound, int value) {
		this.lowerBound = lowerBound;
		this.upperBound = upperBound;
		this.value = value;
	}

	@Override
	public HyperParameter getRandomNeighbor() {
		int range = upperBound - lowerBound;
		int randomValue = lowerBound + Constants.RANDOM.nextInt(range);

		return new DiscreteHP(lowerBound, upperBound, randomValue);
	}

	/**
	 * @return the lowerBound
	 */
	public double getLowerBound() {
		return lowerBound;
	}

	/**
	 * @return the upperBound
	 */
	public double getUpperBound() {
		return upperBound;
	}

	/**
	 * @return the value
	 */
	public double getValue() {
		return value;
	}

	public boolean equals(HyperParameter hyperParameter) {
		if (hyperParameter instanceof DiscreteHP) {
			DiscreteHP rhs = (DiscreteHP) hyperParameter;
			if (this.lowerBound == rhs.getLowerBound()
					&& this.upperBound == rhs.getUpperBound()
					&& this.value == rhs.getValue()) {
				return true;
			}
		}

		return false;
	}

	public String toString() {
		String str = Integer.toString(value);
		return str;
	}
}
